package com.rc.saas.tenant.base;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.rc.saas.tenant.common.constant.ShiroConstants;
import com.rc.saas.tenant.model.tenant.TenantUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;

/**
 * model基类
 */
public abstract class BaseModel implements Serializable {
    @ExcelIgnore
    private String tenantCode; //运营商
    @ExcelIgnore
    private String tenantOperatorCode;//二级运营商
    @ExcelIgnore
    private String createdBy;

    @ExcelIgnore
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdTime;

    @ExcelIgnore
    private String lastUpdatedBy;

    @ExcelIgnore
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastUpdatedTime;

    public BaseModel() {
        Session session = SecurityUtils.getSubject().getSession();
        TenantUser user = (TenantUser) session.getAttribute(ShiroConstants.SESSION_TENANT_USER_KEY);
        if (user != null) {
            this.tenantCode = user.getTenantCode();
            this.tenantOperatorCode = user.getTenantOperatorCode();
        }
    }

    //    @Transient
    // 动态参数加入
    @ExcelIgnore
    public HashMap<String, Object> params = new HashMap<String, Object>();

    public HashMap<String, Object> getParams() {
        return params;
    }

    public void setParams(HashMap<String, Object> params) {
        this.params = params;
    }

    public String getTenantCode() {
        return tenantCode;
    }

    public void setTenantCode(String tenantCode) {
        this.tenantCode = tenantCode;
    }

    public String getTenantOperatorCode() {
        return tenantOperatorCode;
    }

    public void setTenantOperatorCode(String tenantOperatorCode) {
        this.tenantOperatorCode = tenantOperatorCode;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    public String getLastUpdatedBy() {
        return lastUpdatedBy;
    }

    public void setLastUpdatedBy(String lastUpdatedBy) {
        this.lastUpdatedBy = lastUpdatedBy;
    }

    public Date getLastUpdatedTime() {
        return lastUpdatedTime;
    }

    public void setLastUpdatedTime(Date lastUpdatedTime) {
        this.lastUpdatedTime = lastUpdatedTime;
    }

}
